<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="file" name="file" id="file" onchange="upload(this)">
    <img src="" id="img">
    <script>
        function getObjectURL(file) {
            var url = null;
            if (window.createObjcectURL != undefined) {
                url = window.createOjcectURL(file);
            } else if (window.URL != undefined) {
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) {
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
        }

        function upload(obj) {
            obj = obj.files[0];
            var url = getObjectURL(obj);
            console.log(obj)
            var reader = new FileReader();
            reader.readAsDataURL(obj);
            reader.onload = function () {
                console.log(this.result);
                document.getElementById("img").setAttribute("src", this.result);
            }
            // document.getElementById("img").setAttribute("src",url);
        }
    </script>
</body>

</html>